package com.yimin.GenCode.imp;

import com.yimin.GenCode.InterfaceS.GenWebApiServer;
import org.springframework.stereotype.Component;

import static com.yimin.GenCode.imp.GetApPathByTypeAndTableNameImp.humpTransition;


@Component
public class GenWebApiServerImp implements GenWebApiServer {


    @Override
    public String genWebApi(String TableName) {


        String MybatisServerName="MybatisServer" +humpTransition(TableName);
        String MybatisServerImpName="mybatisServerImp" +humpTransition(TableName);

        String EntityClassName="Entity" +humpTransition(TableName);
        String EntityObjectName="entity" +humpTransition(TableName);

        String headFileContent="package com.yimin.controller;" +
                "\n" +
                "\n" +
                "import com.yimin.eneity."+EntityClassName+"; \n" +
                "import com.yimin.eneity.mapper."+MybatisServerName+"; \n"+
                "\n" +
                "\n" +
                "import org.springframework.web.bind.annotation.GetMapping;\n" +
                "import org.springframework.web.bind.annotation.RequestMapping;\n" +
                "import org.springframework.web.bind.annotation.RestController;\n" +
                "\n" +
                "import javax.annotation.Resource;\n" +
                "import java.util.List;" +
                "\n" +
                "\n" +
                "@RestController\n" +
                "@RequestMapping(\""+humpTransition(TableName)+"\")\n" +
                "public class "+humpTransition(TableName)+"ApiController {\n" +
                "\n" +
                "\n" +
                "   @Resource \n" +
                "   MybatisServer" +humpTransition(TableName)+" "+MybatisServerImpName+";\n" +
                "\n" +
                "\n";



        String AddSignApiContent="" +
                "    @PostMapping(\"add\")\n" +
                "    String add(@RequestBody "+EntityClassName+" "+EntityObjectName+"){\n" +
                "    " +MybatisServerImpName+".AddgenCodeUser("+EntityObjectName+");"+
                "\n" +
                "\n" +
                "     return \"增加成功\";\n" +
                "    }\n";

        String DeleteSignApiContent="" +
                "    @PostMapping(\"delete\")\n" +
                "    String delete(@RequestBody "+EntityClassName+" "+EntityObjectName+"){\n" +
                "    " +MybatisServerImpName+".DeletegenCodeUser("+EntityObjectName+");"+
                "\n" +
                "\n" +
                "     return \"删除成功\";\n" +
                "    }\n";

        String UpdateSignApiContent="" +
                "    @PostMapping(\"update\")\n" +
                "    String update(@RequestBody "+EntityClassName+" "+EntityObjectName+"){\n" +
                "    " +MybatisServerImpName+".UpdategenCodeUser("+EntityObjectName+");"+
                "\n" +
                "\n" +
                "     return \"修改成功\";\n" +
                "    }\n";

        String QuerySignApiContent="" +
                "    @PostMapping(\"query\")\n" +
                "    String query(@RequestBody "+EntityClassName+" "+EntityObjectName+"){\n" +
                "    return " +MybatisServerImpName+".QuerygenCodeUser("+EntityObjectName+");"+
                "\n" +
                "\n" +
                "    }\n";;



       String endFileContent="}";



        return headFileContent+AddSignApiContent+DeleteSignApiContent +UpdateSignApiContent+QuerySignApiContent+endFileContent;
    }



}
